<?php

defined('IN_IA') or exit('Access Denied');


require 'model/phpQuery.php';
require 'model/QueryList.php';

include "lib/Wxadoc.php";
include "lib/function.php";
include "model/manger.mod.php";
include "model/bargain.mod.php";
include "lib/WxpayAPI_php_v3/WxpayAPI_php_v3.php";

class bh_bargainModuleSite extends WeModuleSite
{

    public $manger = '';
    public $bargain = '';

    public $siteRoot = '';

    public $w = array();
    public $gpc = array();

    protected $filter = array(
        'ph0001.hezyq.com',
    );

    /**
     * bh_voteModuleSite constructor.
     */

    public function __construct()
    {
        global $_GPC, $_W;
        $this->gpc = $_GPC;
        $this->w = $_W;
        define('UNIACID', $this->w['uniacid']);
        $this->manger = new manger();
        $this->bargain = new bargain();
        $this->siteRoot = $this->w['siteroot'];

    }

    /**
     *  基本配置
     */
    public function doWebConfig()
    {
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        $crontab = $this->w['siteroot'] . "app/index.php?i={$this->w['uniacid']}&from=wxapp&c=entry&a=wxapp&do=crontab&m=bh_bargain";
        $bargaining = $this->w['siteroot'] . "app/index.php?i={$this->w['uniacid']}&from=wxapp&c=entry&a=wxapp&do=bargaining&m=bh_bargain";
        $KjCrontabDy = $this->w['siteroot'] . "app/index.php?i={$this->w['uniacid']}&from=wxapp&c=entry&a=wxapp&do=KjCrontabDy&m=bh_bargain";
        $activitySend = $this->w['siteroot'] . "app/index.php?i={$this->w['uniacid']}&from=wxapp&c=entry&a=wxapp&do=activitySend&m=bh_bargain";
        $signRemind = $this->w['siteroot'] . "app/index.php?i={$this->w['uniacid']}&from=wxapp&c=entry&a=wxapp&do=signRemind&m=bh_bargain";
        $keys = array(
            'ordinary' => array(
                array('key' => 'xcx_title'),
                array('key' => 'old_bargain_number', 'default' => 1),
                array('key' => 'audit_model', 'default' => 1),
                array('key' => 'open_bag', 'default' => 1),
                array('key' => 'is_bargain_video', 'default' => 1),
                array('key' => 'integral_name'),
                array('key' => 'bargain_demo_time'),
                array('key' => 'bargain_demo_appid'),
                array('key' => 'special_reminder'),
                array('key' => 'red_grant_hour'),
                array('key' => 'red_grant_minute'),
                array('key' => 'auth_integral'),
                array('key' => 'auth_phone'),
                array('key' => 'every_day_number'),
                array('key' => 'show_share_people', 'default' => 1),

            ),
            'share' => array(
                array('key' => 'share_text'),
                array('key' => 'share_image'),
            ),
            'redPackets' => array(
                array('key' => 'red_video_open'),
                array('key' => 'red_number'),
            ),
            'pdd' => array(
                array('key' => 'popular_recommend'),
                array('key' => 'pdd_switch'),
                array('key' => 'pdd_navigation_name'),
                array('key' => 'pdd_client_id'),
                array('key' => 'pdd_client_secret'),
                array('key' => 'pdd_pid', 'default' => '8311880_50547417'),
                array('key' => 'ppd_commission', 'default' => 10),
            ),
            'withdrawals' => array(
                array('key' => 'open_withdrawal', 'default' => 1),
                array('key' => 'first_presentation'),
                array('key' => 'cash_reviewed'),
                array('key' => 'follow_up_presentation'),
                array('key' => 'bag_daily_upper'),
                array('key' => 'withdrawal_day_frequency'),
                array('key' => 'sign_days'),
                array('key' => 'cash_type'),
                array('key' => 'cash_bg'),
                array('key' => 'cash_explain'),
                array('key' => 'apiclient_cert'),
                array('key' => 'apiclient_key'),
                array('key' => 'bag_daily_upper'),
                array('key' => 'withdrawals_day_number'),
                array('key' => 'cash_reviewed'),
                array('key' => 'my_withdrawal_txt', 'default' => '现金奖励'),
                array('key' => 'withdrawal_button_txt', 'default' => '提现'),
            ),
            'answer' => array(
                array('key' => 'answer_reward', 'default' => 3),
                array('key' => 'answer_status', 'default' => 2),
                array('key' => 'answer_status', 'default' => 2),
                array('key' => 'answer_double', 'default' => 2),
            ),
            'diyUi' => array(
                array('key' => 'user_bg'),
                array('key' => 'hd_rule_img_top'),
                array('key' => 'cj_rule_img_top'),
                array('key' => 'bargain_img'),
                array('key' => 'bargain_poster_bg'),
                array('key' => 'home_bg'),
                array('key' => 'circle_img'),
                array('key' => 'pop_gold'),
                array('key' => 'bargain_style'),
                array('key' => 'coin_font_color'),
                array('key' => 'roll_content_bg'),
            ),
            'advertising' => array(
                array('key' => 'video_id'),
                array('key' => 'screen_id'),
                array('key' => 'banner_id'),
                array('key' => 'video_ad_id'),
                array('key' => 'luck_ad'),
                array('key' => 'sign_ad'),
                array('key' => 'my_ad'),
                array('key' => 'goods_ad'),
                array('key' => 'bargain_ad'),
                array('key' => 'luck_details_ad'),
                array('key' => 'luck_join'),
                array('key' => 'goods_bargain_ad'),
                array('key' => 'goods_list_bargain_ad'),
                array('key' => 'full_screen_ad'),
                array('key' => 'single_ad'),
                array('key' => 'ad_time', 'default' => 5),
            ),
            'sigin' => array(
                array('key' => 'sigin_title'),
                array('key' => 'is_double', 'default' => 1),
                array('key' => 'sign_subscribe'),
                array('key' => 'sign_subscribe_send_hour'),
                array('key' => 'sign_subscribe_send_minute'),
                array('key' => 'signin_one_day'),
                array('key' => 'signin_two_day'),
                array('key' => 'signin_three_day'),
                array('key' => 'signin_four_day'),
                array('key' => 'signin_five_day'),
                array('key' => 'signin_six_day'),
                array('key' => 'signin_seven_day'),
                array('key' => 'get_group'),
            ),
            'luck' => array(
                array('key' => 'dy_send_message_kj_id'),
                array('key' => 'dy_bargaining_process_id'),
                array('key' => 'new_activities'),
                array('key' => 'info_code_tips'),
                array('key' => 'luck_title'),
            ),

        );

        $op = $this->get('op', 'ordinary');
        if (!isset($keys[$op])) {
            message('参数错误', $this->createWebUrl('config'));
        }

        if ($this->w['ispost']) {
            foreach ($keys[$op] as $value) {
                $names = array('share_image');
                if (!in_array($value['key'], array('apiclient_cert', 'apiclient_key', 'qq_apiclient_cert', 'qq_apiclient_key'))) {
                    $val = in_array($value['key'], $names) ? $this->get($value['key']) : $this->get($value['key']);
                    p_update('config', array('value' => $val), array('key' => $value['key']));
                }

                if ($value['key'] == 'exchange_note') {
                    $exchange_note = $this->get('exchange_note');
                    p_update('config', array('value' => json_encode($exchange_note)), array('key' => $value['key']));
                    continue;
                }

                if ($value['key'] == 'baduanjin_images') {
                    $baduanjin_images = $this->get('baduanjin_images');
                    p_update('config', array('value' => json_encode($baduanjin_images)), array('key' => $value['key']));
                    continue;
                }

                if ($value['key'] == 'cash_money') {
                    $cash_money = $this->get('cash_money');
                    p_update('config', array('value' => json_encode($cash_money)), array('key' => $value['key']));
                    continue;
                }


                if ($value['key'] == 'cash_explain') {
                    $cash_explain = $this->get('cash_explain');
                    p_update('config', array('value' => json_encode($cash_explain)), array('key' => $value['key']));
                    continue;
                }
            }

            $path1 = ATTACHMENT_ROOT . $this->w['uniacid'] . 'cert/';
            if (!file_exists($path1)) {
                @mkdir($path1, 0777, true);
            }


            if (isset($_FILES['_apiclient_cert']['tmp_name']) && file_exists($_FILES['_apiclient_cert']['tmp_name'])) {
                $path = $path1 . 'apiclient_cert.pem';

                if (move_uploaded_file($_FILES['_apiclient_cert']['tmp_name'], $path)) {
                    p_update('config', array('value' => $path), array('key' => 'apiclient_cert'));
                }
            }
            if (isset($_FILES['_apiclient_key']['tmp_name']) && file_exists($_FILES['_apiclient_key']['tmp_name'])) {
                $path = $path1 . 'apiclient_key.pem';
                if (move_uploaded_file($_FILES['_apiclient_key']['tmp_name'], $path)) {
                    p_update('config', array('value' => $path), array('key' => 'apiclient_key'));
                }
            }


            if (isset($_FILES['_qq_apiclient_cert']['tmp_name']) && file_exists($_FILES['_qq_apiclient_cert']['tmp_name'])) {
                $path = $path1 . 'apiclient_cert.pem';
                if (move_uploaded_file($_FILES['_qq_apiclient_cert']['tmp_name'], $path)) {
                    p_update('config', array('value' => $path), array('key' => 'qq_apiclient_cert'));
                }
            }
            if (isset($_FILES['_qq_apiclient_key']['tmp_name']) && file_exists($_FILES['_qq_apiclient_key']['tmp_name'])) {
                $path = $path1 . 'apiclient_key.pem';
                if (move_uploaded_file($_FILES['_qq_apiclient_key']['tmp_name'], $path)) {
                    p_update('config', array('value' => $path), array('key' => 'qq_apiclient_key'));
                }
            }


        }
        $initial = function ($key, $default = 0) {
            $config = p_get('config', array('key' => $key));
            if (empty($config)) {
                $config = array(
                    'key' => $key,
                    'value' => $default
                );
                p_insert('config', $config);
            }
            return $config;
        };
        foreach ($keys[$op] as $value) {
            $k = $value['key'];
            $$k = $initial($k, $value['default']);
        }

        $basename = pathinfo($this->w["siteroot"]);
        $basename = $basename["basename"];
        $w7_order_id = p_get('config', array('key' => "w7_order_id"));
        $activation_code = p_get('config', array('key' => "activation_code"));
        $w7_order_ids = '123456';
        if (empty($w7_order_id)) {
            p_insert('config', array("key" => "w7_order_id", "value" => md5($basename . "1fdfd4c01357071e9fa6328a9d330c" . $w7_order_ids)));
        } else {
            p_update('config', array('value' => md5($basename . "1fdfd4c01357071e9fa6328a9d330c" . $w7_order_ids)), array('key' => 'w7_order_id'));
        }
        $w7_order_id = p_get('config', array('key' => "w7_order_id"));
        if (empty($activation_code)) {
            p_insert('config', array("key" => "activation_code", "value" => md5($basename . "1fdfd4c01357071e9fa6328a9d330c" . $w7_order_id)));
        } else {
            p_update('config', array('value' => md5($basename . "1fdfd4c01357071e9fa6328a9d330c" . $w7_order_id)), array('key' => 'activation_code'));
        }

        if ($op == 'diyUi') {
            $baduanjin_images['value'] = !empty($baduanjin_images['value']) ? json_decode($baduanjin_images['value'], true) : array(0 => '');
        }
        if ($op == 'ordinary') {
            $exchange_note['value'] = !empty($exchange_note['value']) ? json_decode($exchange_note['value'], true) : array(0 => '');
            $exchange_amount['value'] = !empty($exchange_amount['value']) ? json_decode($exchange_amount['value'], true) : array(0 => '');
        }
        if ($op == 'withdrawals') {
            $cash_explain['value'] = !empty($cash_explain['value']) ? json_decode($cash_explain['value'], true) : array(0 => '');
            $cash_money['value'] = !empty($cash_money['value']) ? json_decode($cash_money['value'], true) : array(0 => '');
        }
        include $this->template('config');
    }


    /**
     * 用户管理
     */
    public function doWebMember()
    {
        $page = $this->get('page');
        $where = "headimgurl != '' " . get_uniacid();
        $id = $this->get('id');
        $member_id = $this->get('member_id');
        $op = $this->get('op');
        if ($op == 'delete') {
            $bool = p_delete('member', array('id' => $id));
            p_delete('day', array('member_id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'updatePhone') {
            $phone = $this->get('phone');
            if (preg_match("/^1[34578]{1}\d{9}$/", $phone)) {
                $bool = p_update('member', array('phone' => $phone), array('id' => $id));
                json('', $bool ? 1 : 0);
            } else {
                json('', 0);
            }
        } elseif ($op == 'block') {
            $bool = p_update('member', array('is_block' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'cancelBlock') {
            $bool = p_update('member', array('is_block' => 1), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND nickname LIKE '%{$nickname}%'";
            }
            if ($member_id) {
                $where .= " AND  id ={$member_id}";
            }
            if ($id) {
                $where .= " AND parent_id={$id}";
            }
            $time = $this->get('time');
            if (!$time) {
                $time = array('start' => '2019-08-01', 'end' => date('Y-m-d', time()));
            }
            $is_fictitious = $this->get('is_fictitious', 0);
            if ($is_fictitious != 0) {
                $where .= " AND is_fictitious = {$is_fictitious}";
            }
            $start = strtotime($time['start']);
            $end = strtotime($time['end']) + 86400;
            $where .= " AND created > {$start} AND created <= {$end}";
            $filed = "id";
            if ($op == 'money_sort' || $op == 'money_r_sort') {
                $filed = 'money';
            }
            if ($op == 'remind_sort' || $op == 'remind_r_sort') {
                $filed = 'remind';
            }
            if ($op == 'currency_sort' || $op == 'currency_r_sort') {
                $filed = 'currency';
            }
            if ($op == 'abnormal_sort' || $op == 'abnormal_r_sort') {
                $filed = 'cash';
            }
            if ($op == 'integral_r_sort' || $op == 'integral_sort') {
                $filed = 'integral';
            }
            $orderBy = "ASC";
            if ($op == 'money_r_sort') {
                $orderBy = "DESC";
            }
            if ($op == 'abnormal_r_sort' || $op == 'integral_r_sort' || $op == 'currency_r_sort' || $op == 'remind_r_sort') {
                $orderBy = "DESC";
            }
            $member = $this->manger->getTableList('member', $page, $where, $filed, $orderBy);
            if ($member['list']) {
                foreach ($member['list'] as & $value) {
                    $value['inviter'] = p_getcolumn('member', array('id' => $value['parent_id']), 'nickname');
                    $value['groupCount'] = p_getcolumn('group', array('member_id' => $value['id']), 'COUNT(*)') ?: 0;
                    $value['taskCount'] = p_getcolumn('task', array('member_id' => $value['id']), 'COUNT(*)') ?: 0;
                    $value['dayCount'] = p_getcolumn('day', array('member_id' => $value['id']), 'SUM(clock)') ?: 0;
                    $value['dayNumber'] = p_getcolumn('day', array('member_id' => $value['id']), 'COUNT(*)') ?: 0;
                    $value['couponCount'] = p_getcolumn('member_coupon', array('member_id' => $value['id']), 'COUNT(*)') ?: 0;
                    $value['inviteNumber'] = p_getcolumn('member', array('parent_id' => $value['id']), 'COUNT(*)') ?: 0;
                }
            }
            $date = date('Y-m-d', time());
            $todayWhere = $this->manger->getTime($date, $date, 'created');
            $todayWhere .= " AND is_fictitious = 1 AND uniacid=" . UNIACID;
            $total = p_getcolumn('member', array('is_fictitious' => 1), 'COUNT(*)');
            $todayMember = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('member') . " WHERE {$todayWhere}");
            include $this->template('member');
        }

    }

    public function doWebPosters()
    {
        $op = $this->get('op');
        if ($op == 'addShow' || $op == 'editShow' || $op == ' delete') {
            $key = $this->get('key');
            $behavior = $this->get('behavior');
            $bool = $this->manger->editPosters($key, $behavior);
            if ($behavior == 'delete') {
                message($bool ? '操作成功' : '操作失败', $this->createWebUrl("posters"), $bool ? 'success' : 'error');
            } else {
                $bool['key'] = $key;
                include $this->template('posters_add');
            }
        } elseif ($op == 'edit') {
            $icon = $this->get('icon');
            $bg = $this->get('bg');
            $key = $this->get('key');
            $color = $this->get('color');
            $bool = $this->manger->editPostersHandle($key, $icon, $bg, $color);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl("posters"), $bool ? 'success' : 'error');
        } elseif ($op == 'add') {
            $icon = $this->get('icon');
            $bg = $this->get('bg');
            $color = $this->get('color');
            $bool = $this->manger->postersHandle($icon, $bg, $color);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl("posters"), $bool ? 'success' : 'error');
        } else {
            $posters = $this->manger->getPosters();
            include $this->template('posters');
        }
    }

    public function doWebMemberCoupon()
    {
        $page = $this->get('page');
        $where = "1 = 1 " . get_uniacid();
        $member_id = $this->get('member_id');
        $op = $this->get('op');

        if ($op == 'delete') {
            $id = $this->get('id');
            p_delete('member_coupon', array('id' => $id));
            json('', 1);
        } else {
            if ($member_id) {
                $where .= " AND member_id ={$member_id}";
            }
            $memberCoupon = $this->manger->getTableList('member_coupon', $page, $where);
            if ($memberCoupon['list']) {
                foreach ($memberCoupon['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['name'] = p_getcolumn('coupon', array('id' => $value['coupon_id']), 'name');
                }
            }
            include $this->template('memberCoupon');
        }
    }


    public function doWebBuy()
    {
        // 1 是商品订单 2是积分订单
        $type = $this->get('type', 1);
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'edit') {
            $member_id = $this->get('member_id');
            if ($type == 1) {
                $data = array(
                    'member_id' => $member_id,
                    'goods_id' => $id,
                    'status' => 2,
                    'deliver_status' => 3,
                    'is_fictitious' => 2,
                    'suc_time' => time()
                );
                $goods = p_get('goods', array('id' => $id));

                $bool = p_insert('order', $data);
                if ($bool) {
                    p_update('goods', array('bargain_number' => $goods['bargain_number'] + 1), array('id' => $goods['id']));
                }
            } else {
                $integralGoods = p_get('integral_goods', array('id' => $id));

                if ($integralGoods['type'] == 1) {
                    $integralData['goods_id'] = $integralGoods['goods_id'];
                }
                if ($integralGoods['type'] == 2) {
                    $integralData['relation_goods_id'] = $integralGoods['relation_goods_id'];
                }
                $integralData['member_id'] = $member_id;
                $integralData['status'] = 3;
                $integralData['is_pay'] = 2;
                $integralData['is_fictitious'] = 2;
                $integralData['type'] = $integralGoods['type'];
                $bool = p_insert('integral_order', $integralData);
                if ($bool) {
                    p_update('integral_goods', array('exchange_num' => $integralGoods['exchange_num'] + 1), array('id' => $integralGoods['id']));
                }
            }
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl($type == 1 ? 'goods' : 'integralGoods'), $bool ? 'success' : 'error');
        } else {
            if ($type == 1) {
                $goods = p_get('goods', array('id' => $id));
                $goods['goods_name'] = $goods['name'];
            } else {
                $goods = p_get('integral_goods', array('id' => $id));
            }
            $member = p_getall('member', array('is_fictitious' => 2));
            include $this->template('buy_add');
        }

    }

    public function doWebFictitious()
    {
        $table = prefix('member', true);
        $where = "uniacid={$this->w['uniacid']} AND is_fictitious = 2";
        $pindex = max(1, intval($this->get('page')));
        $psize = 20;
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addshow") {
            include $this->template('fictitious_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'nickname' => $this->get('nickname'),
                'headimgurl' => tomedia($this->get('headimgurl')),
                'integral' => $this->get('integral'),
                'created' => time(),
                'openid' => $this->getIssueNumber(12) . $this->w['uniacid'],
                'is_fictitious' => 2
            );
            //var_dump($data);die;
            $bool = !empty($id) ? p_update('member', $data, array('id' => $id)) : p_insert('member', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('fictitious'), $bool ? 'success' : 'error');
        } elseif ($op == 'edit_show') {
            $id = $this->get('id');
            $memberData = p_get('member', array('id' => $id));
            include $this->template('fictitious_add');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('member', array('id' => $id));
            json('1');
        } else {

            $list = p_fetchall('SELECT * FROM ' . $table . " WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);

            $total = p_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");

            $pager = pagination($total, $pindex, $psize);

            include $this->template('fictitious');

        }

    }


    public function doWebSubscribe()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            include $this->template('subscrib_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $activityName = $this->get('activityName');
            $activityTime = $this->get('activityTime');
            $activityText = $this->get('activityText');
            $skipUrl = $this->get('skipUrl');
            if ($op == 'add') {
                $bool = $this->manger->subscribeQueue($activityName, $activityTime, $activityText, $skipUrl);
            } else {
                $bool = $this->manger->subscribeQueue($activityName, $activityTime, $activityText, $skipUrl, $id);
            }
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('subscribe'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('subscribe_queue', array('id' => $id));
            json('1');
        } elseif ($op == 'cancelSuspend' || $op == 'suspend') {
            $status = $this->get('status');
            p_update('subscribe_queue', array('status' => $status), array('id' => $id));
            json('', 1);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $subscribeQueue = $this->manger->getTableList('subscribe_queue', $page, $where);
            if ($subscribeQueue['list']) {
                $status = array(
                    1 => '发送中',
                    2 => '发送完成',
                    3 => '停止'
                );
                foreach ($subscribeQueue['list'] as & $value) {
                    $value['status'] = $status[$value['status']];
                    $value['content'] = json_decode($value['content'], true);
                }
            }
            include $this->template('subscrib');
        }

    }

    public function doWebLuck()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        if ($op == "addShow" || $op == 'editShow') {
            $luck = p_get('luck', array('id' => $id));
            $goods = p_get('luck_goods', array('luck_id' => $id));

            $luck['name'] = $goods['name'];
            $luck['number'] = $goods['number'];
            $luck['image'] = $goods['image'];
            $luck['type_type'] = $luck['sponsor_text']['type'];

            if ($luck['type_type'] == 2) {
                $luck['sponsor_text'] = json_decode($luck['sponsor_text'], true);
                $luck['appid'] = $luck['sponsor_text']['appid'];
                $luck['path'] = $luck['sponsor_text']['path'];
            }
            if ($luck['type_type'] == 1) {
                $luck['image'] = $luck['sponsor_text']['image'];
            }

            include $this->template('luck_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'lottery_type' => $this->get('lottery_type'),
                'luck_mode' => $this->get('luck_mode'),
                'sponsor_type' => $this->get('sponsor_type'),
                'lottery_explain' => $this->get('lottery_explain'),
                'image_text' => $this->get('image_text'),
                'sponsor' => $this->get('sponsor'),
            );
            if (in_array($data['lottery_type'], array(1, 2))) {
                $lottery_value = $this->get('lottery_value');
                $data['lottery_value'] = $data['lottery_type'] == 1 ? strtotime($lottery_value) : $this->get('lottery_value_s');
            }
            $goods = array(
                'name' => $this->get('name'),
                'image' => $this->get('image'),
                'number' => $this->get('number'),
            );
            if ($data['luck_mode'] == 2) {
                $data['team_number'] = $this->get('team_number');
                if ($goods['number'] % $data['team_number'] > 0) {
                    message("奖品数量必须为成团人数的整数倍", $this->createWebUrl("Luck"), 'error');
                }
            }
            if ($data['luck_mode'] == 4) {
                $data['luck_pwd'] = $this->get('luck_pwd');
            }
            if (in_array($data['sponsor_type'], array(1, 3))) {
                $data['sponsor_text'] = $data['sponsor_type'] == 1 ? $this->get('sponsor_text') : $this->get('sponsor_text_c');


            } else {
                $type_type = $this->get('type_type');
                if ($type_type == 1) {
                    $sponsor = array(
                        'type' => $type_type,
                        'image' => $this->get('sponsor_image'),
                    );
                } else {
                    $sponsor = array(
                        'type' => $type_type,
                        'appid' => $this->get('appid'),
                        'path' => $this->get('path'),
                    );
                }
                $data['sponsor_text'] = json_encode($sponsor);
            }
            $data['prize_number'] = $goods['number'];
            $data['complete'] = 2;
            $data['is_ad'] = $this->get('is_ad');
            $data['loop'] = $this->get('loop');
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $this->manger->changeLuck($data, $goods, $id);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('luck'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('luck', array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $luck = $this->manger->getTableList('luck', $page, $where);
            if ($luck['list']) {
                $lottery_type = array(
                    1 => '时间自动开奖',
                    2 => '人数开奖',
                    3 => '手动开奖',
                    4 => '现场抽奖',
                );
                $luck_mode = array(
                    1 => '普通抽奖',
                    2 => '组队抽奖',
                    3 => '抽奖码',
                    4 => '口令抽奖'
                );
                $status = array(
                    1 => '进行中',
                    2 => '已结束',
                    3 => '失败',
                );
                foreach ($luck['list'] as & $value) {
                    $value['lottery_type'] = $lottery_type[$value['lottery_type']];
                    $value['luckMode'] = $luck_mode[$value['luck_mode']];
                    $value['state'] = $status[$value['status']];
                    $value['goods'] = p_get('luck_goods', array('luck_id' => $value['id']));
                }
            }
            include $this->template('luck');
        }

    }

    public function doWebPartyLuck()
    {
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'appoint') {
            $luck_goods_id = $this->get('luck_goods_id');
            $luck_group_id = $this->get('luck_group_id');
            if ($luck_group_id && $luck_goods_id) {
                $bool = p_update('luck_group', array('is_appoint' => 2, 'appoint_goods_id' => $luck_goods_id), array('id' => $luck_group_id));
                message($bool ? '指定成功' : '指定失败', $this->createWebUrl('luck'), $bool ? 'success' : 'error');
            } else {
                message('团长不存在或者商品不存在', $this->createWebUrl('luck'), 'error');
            }
        } else {
            if ($id) {
                $luckGroup = p_fetchall("SELECT * FROM " . prefix('luck_group') . " WHERE luck_id={$id}  AND is_appoint = 1");
                foreach ($luckGroup as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                }
                $luckGoods = p_fetchall("SELECT * FROM " . prefix('luck_goods') . " WHERE luck_id={$id}");
            }
            include $this->template('partyLuck');
        }

    }


    public function doWebCheckGoods()
    {

        $op = $this->get('op');
        if ($op == 'delete') {
            $id = $this->get('id');
            $luckGoods = p_get('luck_goods', array('id' => $id));
            $luck = p_get('luck', array('id' => $luckGoods['luck_id']));
            if ($luckGoods && $luck) {
                p_update('luck', array('prize_number' => $luck['prize_number'] - $luckGoods['number']), array('id' => $luck['id']));
                p_delete('luck_goods', array('id' => $id));
                p_delete('luck_goods_info', array('luck_goods_id' => $id));
            }
            json('', 1);
        } else {
            $luck_id = $this->get('id');
            $page = $this->get('page');
            $where = "luck_id = {$luck_id} " . get_uniacid();
            $type = array(
                1 => '实物',
                2 => '虚拟',
                3 => '红包',
            );
            $luckGoods = $this->manger->getTableList('luck_goods', $page, $where);
            if ($luckGoods['list']) {
                foreach ($luckGoods['list'] as & $value) {
                    $value['image'] = $value['image'] ?: $this->images('prize_default_picture', 'prize_default_picture.png');
                    $value['nickname'] = pdo_getcolumn(PREFIX . 'memberinfo', array('id' => $value['member_id']), 'nickname');
                    $value['in_prize'] = $this->manger->getLuckIsPrize($value['id'], $value['goods_id']);
                    $value['type'] = $type[$value['type']];
                }
            }
            include $this->template('luck_behavior');
        }

    }


    public function doWebLuckAddGood()
    {
        $luck_id = $this->get('luckId');
        $op = $this->get('op');
        if ($op == 'add') {
            $luckId = $this->get('luck_id');
            $name = $this->get('name');
            $coverImage = $this->get('cover_image');
            $number = $this->get('number');
            $type = $this->get('type');
            $fictitious = $this->get('fictitious');
            $fictitiousData = array();
            $redData = array();
            if ($type == 2) {
                $fictitiousData = explode(',', $fictitious);
                if ($number != count($fictitiousData)) {
                    message('兑换码和分数不相等', $this->createWebUrl('luck'), 'error');
                }
            }
            if ($type == 3) {
                $redData = array(
                    'red_type' => $this->get('red_type'),
                    'red_money' => $this->get('red_money')
                );
                $this->manger->delPhysical($luckId);


            }

            if (p_get('luck_goods', array('type' => 3, 'luck_id' => $luckId)) && $type == 1) {
                message('红包商品存在不能再添加实物', $this->createWebUrl('luck'));
            }
            $bool = $this->manger->addVoteGoods($luckId, $name, $coverImage, $number, $type, $fictitiousData, $redData);
            message($bool ? '成功' : '失败', $this->createWebUrl('luck'));
        } else {
            include $this->template('luck_goods_2');
        }

    }


    public function doWebCs()
    {
        $data = $this->manger->getRedTwo(10 * 100, 10);
        foreach ($data as $va) {
            echo '红包金额为:' . number_format($va / 100, 2) . '元' . '<br>';
        }
        var_export(array_sum($data));
        var_export($data);
    }

    public function doWebLuckAssign()
    {
        $op = $this->get('op');
        if ($op == 'assign') {
            $memberId = $this->get('member_id');
            $luckId = $this->get('luck_id');
            $luck_goods_info_id = $this->get('luck_goods_info_id');
            $bool = $this->manger->addLuckAssign($luckId, $memberId, $luck_goods_info_id);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl("Luck"), $bool ? 'success' : 'error');
        } else {
            $luck_goods_info_id = $this->get('luck_goods_info_id');
            $luck_id = $this->get('luck_id');
            include $this->template('luck_assign');
        }

    }


    public function doWebGetLuckParticipate()
    {
        $nickname = $this->get('nickname');
        $luck_id = $this->get('luck_id');
        $table = prefix('luck_participate');
        $nData = array();
        if ($nickname) {
            $where = " member_id in ({$this->manger->getMemberId($nickname)})";
            if ($luck_id) {
                $where .= " AND luck_id={$luck_id}";
            }
            $nData = p_fetchall("SELECT member_id FROM {$table} WHERE {$where} ORDER BY id DESC ");
            if ($nData) {
                foreach ($nData as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                }
            }
        }
        json($this->getStr($nData));
    }

    protected function getStr($nData)
    {
        $str = "<option value='0'>请选择</option>";
        if ($nData) {
            foreach ($nData as $val) {
                $str .= "<option value='" . $val['member_id'] . "'>{$val['member_id']}-{$val['nickname']}</option>";
            }
        }
        return $str;
    }


    public function doWebCheckGoodsDetails()
    {
        $luck_id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'cancel') {
            $luck_id = $this->get('luck_id');
            $goods_id = $this->get('goods_id');
            $bool = $this->manger->cancelLuck($luck_id, $goods_id);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl("Luck"), $bool ? 'success' : 'error');
        } else {
            $luckGoodsDetails = p_getall('luck_goods_info', array('luck_id' => $luck_id));
            $type = array(
                1 => '实物',
                2 => '虚拟',
                3 => '红包'
            );
            if ($luckGoodsDetails) {
                foreach ($luckGoodsDetails as & $vl) {
                    $vl['type'] = $type[$vl['type']];
                }
            }
            include $this->template('luck_goods_assign');
        }

    }


    public function doWebLuckInteract()
    {

        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'append') {

            $memberId = $this->get('member_id');
            $luckId = $this->get('luck_id');
            $goods_id = $this->get('goods_id', 0);
            $luck = p_get('luck', array('id' => $luckId));
            if (is_array($memberId)) {
                $bool = true;
                foreach ($memberId as $value) {
                    if (!$this->manger->addLuckPeople($luckId, $value, $goods_id)) {
                        $bool = false;
                    } else {
                        if ($luck['luck_mode'] == 3) {
                            $this->manger->create_luck_code($value, $luckId);
                        }
                    }
                }
            } else {
                $bool = $this->manger->addLuckPeople($luckId, $memberId, $goods_id);
                if ($bool) {
                    if ($luck['luck_mode'] == 3) {
                        $this->manger->create_luck_code($memberId, $luckId);
                    }
                }
            }
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl("luck"), $bool ? 'success' : 'error');

        } else {
            $luckGoods = p_getall('luck_goods', array('luck_id' => $id), array('goods_id', 'name'));
            $member = p_fetchall("SELECT id,nickname FROM " . prefix('member') . " WHERE is_fictitious = 2 ORDER BY id desc LIMIT 0, 900");
            include $this->template('luck_interact');
        }

    }

    public function doWebCondition()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            $condition = p_get('withdrawals_condition', array('id' => $id));
            include $this->template('condition_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'number' => $this->get('number'),
                'click_day' => $this->get('click_day'),
                'share_num' => $this->get('share_num'),
                'money' => $this->get('money'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = !empty($id) ? p_update('withdrawals_condition', $data, array('id' => $id)) : p_insert('withdrawals_condition', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('condition'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('withdrawals_condition', array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $condition = $this->manger->getTableList('withdrawals_condition', $page, $where);
            include $this->template('condition');
        }

    }

    public function doWebCoupon()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            $coupon = p_get('coupon', array('id' => $id));
            include $this->template('coupon_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'name' => $this->get('name'),
                'icon' => $this->get('icon'),
                'worth' => $this->get('worth'),
                'validity' => $this->get('validity'),
                'integral' => $this->get('integral'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = !empty($id) ? p_update('coupon', $data, array('id' => $id)) : p_insert('coupon', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('coupon'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_update('coupon', array('is_delete' => 2), array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "is_delete = 1 " . get_uniacid();
            $coupon = $this->manger->getTableList('coupon', $page, $where);
            include $this->template('coupon');
        }

    }

    public function doWebBatch()
    {
        $member = p_fetchall('SELECT * FROM ' . prefix('member') . " WHERE is_fictitious = 1 ORDER BY id DESC LIMIT 0, 100");
        if ($member) {
            foreach ($member as $value) {
                $data = array(
                    'nickname' => '达人' . mt_rand(1, 9999),
                    'headimgurl' => $value['headimgurl'],
                    'integral' => mt_rand(1000, 900000),
                    'money' => mt_rand(1, 600),
                    'created' => time(),
                    'openid' => mt_rand(1, 3679) . $this->getIssueNumber(8) . $this->w['uniacid'],
                    'is_fictitious' => 2
                );

                p_insert('member', $data);
            }
        }
        message('操作成功', $this->createWebUrl('fictitious'), 'success');
    }

    public function doWebMoneyLog()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('money_log', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            $member_id = $this->get('member_id');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            if ($member_id) {
                $where .= " AND member_id ={$member_id}";
            }
            $moneyLog = $this->manger->getTableList('money_log', $page, $where);
            if ($moneyLog['list']) {
                $type = array(
                    1 => '领取红包',
                    2 => '兑换红包商品',
                    3 => '提现',
                    4 => '抽奖红包',
                    5 => '积分兑换红包'
                );
                foreach ($moneyLog['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['type'] = $type[$value['type']];
                }
            }
            include $this->template('money_log');
        }

    }


    public function doWebGraphic()
    {
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('new', array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'addShow' || $op == 'editShow') {
            $graphic = p_get('new', array('id' => $id));
            include $this->template('graphic_add');
        } elseif ($op == 'add' || $op == 'edit') {

            $data = array(
                'title' => $this->get('title'),
                'subtitle' => $this->get('subtitle'),
                'cover_image' => $this->get('cover_image'),
                'author' => $this->get('author'),
                'author_image' => $this->get('author_image'),
                'browse' => $this->get('browse'),
                'content' => $this->get('content'),
                'state' => $this->get('state'),
                'sort' => $this->get('sort'),
                'created' => strtotime($this->get('created')),
            );
            $bool = $id ? p_update('new', $data, array('id' => $id)) : p_insert('new', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('graphic'), $bool ? 'success' : 'error');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            $graphic = $this->manger->getTableList('new', $page, $where);

            include $this->template('graphic');
        }

    }

    public function doWebSystemDay()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('system_day', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            $system_day = $this->manger->getTableList('system_day', $page, $where);
            if ($system_day['list']) {
                $type = array(
                    1 => '分红',
                    2 => '提现',
                );
                foreach ($system_day['list'] as & $value) {
                    $value['type'] = $type[$value['type']];
                }
            }
            $graphic = $this->rising->isGraphic() ? 1 : 0;
            include $this->template('system_day');
        }

    }


    public function doWebDay()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('day', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "member_id = {$id} " . get_uniacid();

            $day = $this->manger->getTableList('day', $page, $where);
            if ($day['list']) {
                $status = array(
                    1 => '未结算',
                    2 => '已结算',
                );
                foreach ($day['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['type'] = $status[$value['status']];
                }
            }
            include $this->template('day');
        }

    }

    public function doWebCurrencyLog()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('currency_log', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            $member_id = $this->get('member_id');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }

            if ($member_id) {
                $where .= " AND member_id = {$member_id}";
            }
            $currencyLog = $this->manger->getTableList('currency_log', $page, $where);
            if ($currencyLog['list']) {
                $type = array(
                    1 => '自己打卡',
                    2 => '一级好友',
                    3 => '二级好友打卡',
                    4 => '虚拟用户打卡',
                    5 => '兑换商品',
                    6 => '分红扣除'
                );
                foreach ($currencyLog['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['type'] = $type[$value['type']];
                }
            }
            $date = date('Y-m-d', time());
            $todayWhere = $this->manger->getTime($date, $date, 'created');
            $todayWhere .= " AND uniacid=" . UNIACID;
            $total = p_getcolumn('currency_log', array(), 'SUM(currency)');
            $todayMember = p_fetchcolumn("SELECT SUM(currency) FROM " . prefix('currency_log') . " WHERE {$todayWhere}");


            $yesterday_start = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')));
            $yesterday_end = date('Y-m-d H:i:s', mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 1);

            $yesterdayWhere = $this->manger->getTime($yesterday_start, $yesterday_end, 'created');
            $yesterdayWhere .= " AND uniacid=" . UNIACID;
            $yesterday = p_fetchcolumn("SELECT SUM(currency) FROM " . prefix('currency_log') . " WHERE {$yesterdayWhere}");
            include $this->template('currency_log');
        }

    }

    public function doWebPhoneBill()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('phone_bill', array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'success') {
            $bool = p_update('phone_bill', array('status' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'waring') {
            $bool = p_update('phone_bill', array('status' => 3), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'successPay') {
            $member = p_get('phone_bill', array('id' => $id));
            $returnData = cost($member['phone'], $member['money']);
            if ($returnData['error_code'] == -1000) {
                json($returnData['reason'], 0);
            }
            p_update('phone_bill', array('status' => 2), array('id' => $id));
            json('', 1);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            if ($status = $this->get('status')) {
                $where .= " AND status ={$status}";
            }
            $phoneBill = $this->manger->getTableList('phone_bill', $page, $where);
            if ($phoneBill['list']) {
                $status = array(
                    1 => '未充值',
                    2 => '已经充值',
                    3 => '拒绝',
                );
                foreach ($phoneBill['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['statusStr'] = $status[$value['status']];
                }
            }
            include $this->template('phone_bill');
        }

    }

    public function doWebGroup()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            $where = "1 = 1 " . get_uniacid();
            $group_type = $this->manger->getTableList('group_type', 1, $where);
            $group = p_get('group', array('id' => $id));
            $select = '';
            foreach ($group_type['list'] as $index => $value){
                $select .=  "<option value={$value['id']}>{$value['name']}</option>";
            }
            include $this->template('group_add');
        }else if ($op == "addType" || $op == 'editType') {
            $group = p_get('group_type', array('id' => $id));
            include $this->template('group_type');
        } elseif ($op == 'addT' || $op == 'editT') {
            $data = array(
                'name' => $this->get('name'),
            );
            $bool = !empty($id) ? p_update('group_type', $data, array('id' => $id)) : p_insert('group_type', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('group', ["op" => "type_list"]), $bool ? 'success' : 'error');
        } elseif($op == "type_list") {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $group = $this->manger->getTableList('group_type', $page, $where);
            include $this->template('group_type_list');
        }elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'name' => $this->get('name'),
                'code' => $this->get('code'),
                'bg' => $this->get('bg'),
                'type' => $this->get('type'),
                'status' => $this->get('status'),
            );
            $bool = !empty($id) ? p_update('group', $data, array('id' => $id)) : p_insert('group', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('group'), $bool ? 'success' : 'error');
        } elseif ($op == 'type_list_delete') {
            $id = $this->get('id');
            p_delete('group_type', array('id' => $id));
            json('1');
        }elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('group', array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $group = $this->manger->getTableList('group', $page, $where);
            $group_type = $this->manger->getTableList('group_type', 1, $where);
            foreach ($group['list'] as $key => $value){
                foreach ($group_type['list'] as $_value){
                    if($value['type'] == $_value['id']){
                        $group['list'][$key]['type'] = $_value['name'];
                        break;
                    }
                }
            }
            include $this->template('group');
        }

    }

    public function doWebSignIn()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'delete') {
            $bool = p_delete('signin', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            $signIn = $this->manger->getTableList('signin', $page, $where);
            if ($signIn['list']) {
                foreach ($signIn['list'] as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                }
            }
            include $this->template('signIn');
        }

    }

    private function setPayment()
    {
        WxPayConfig::$APPID = $this->w['uniaccount']['key'];
        WxPayConfig::$MCHID = $this->w['account']['setting']['payment']['wechat']['mchid'];
        WxPayConfig::$KEY = $this->w['account']['setting']['payment']['wechat']['signkey'];
        WxPayConfig::$APPSECRET = $this->w['uniaccount']['secret'];

        $apiclient_cert = getConfig('apiclient_cert');
        if (!empty($apiclient_cert)) {
            WxPayConfig::$SSLCERT_PATH = $apiclient_cert;
        }
        $apiclient_key = getConfig('apiclient_key');
        if (!empty($apiclient_key)) {
            WxPayConfig::$SSLKEY_PATH = $apiclient_key;
        }
    }


    /**
     *  提现管理
     */
    public function doWebWithdrawals()
    {
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        $op = $this->get('op');
        if ($op == 'sgree') {
            $id = $this->get('id');
            $cash = p_get('withdrawals', array('id' => $id));
            if ($cash['status'] > 1) {
                json(1);
            }
            $cash_type = getConfig('cash_type', 1);
            if ($cash_type == 2) {
                p_update('withdrawals', array('status' => 2), array('id' => $id));
                json(1);
            } else {
                pdo_begin();
                try {
                    $this->setPayment();
                    if (!p_update('withdrawals', array('status' => 2, 'success_time' => time()), array('id' => $id, 'status' => 1))) {
                        throw new Exception('提现失败');
                    }
                    if (getConfig('qq_mch_id')) {
                        if (!$this->bargain->qqCash($cash['member_id'], $cash['money'], '', $cash['id'])) {
                            throw new Exception($this->bargain->error);
                        }
                    } else {
                        if (!$this->bargain->cash($cash['money'], $cash['member_id'])) {
                            throw new Exception($this->bargain->error);
                        }
                    }

                    pdo_commit();
                    json(1);
                } catch (Exception $e) {
                    pdo_rollback();
                    json($e->getMessage(), 0);
                }
            }

        } elseif ($op == 'refuse') {
            $id = $this->get('id');
            $cash = p_get('withdrawals', array('id' => $id));
            if ($cash['status'] > 1) {
                json(1);
            }
            p_update('withdrawals', array('status' => 3), array('id' => $id));
            json(1);
        } else {
            $table = prefix('withdrawals');
            $where = "uniacid=" . UNIACID;
            $status = $this->get('status', 0);
            if ($status > 0) {
                $where .= " AND status={$status}";
            }
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)}) ";
            }
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $list = p_fetchall("SELECT * FROM {$table} WHERE {$where}  ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            $statusStr = array(
                1 => '申请成功',
                2 => '提现成功',
                3 => '提现失败'
            );
            if ($list) {
                foreach ($list as & $value) {
                    $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['type'] = $value['type'] == 1 ? '企业零钱' : '收款码';
                    $value['statusStr'] = $statusStr[$value['status']];
                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);

            $totalMoney = p_getcolumn('withdrawals', array('status' => 2), 'SUM(money)');
            $date = date('Y-m-d', time());

            $todayWhere = $this->manger->getTime($date, $date, 'created');
            $todayWhere .= " AND status =2 AND uniacid =" . UNIACID;
            $todayMoney = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('withdrawals') . " WHERE {$todayWhere}");

            $todayWhere1 = $this->manger->getTime($date, $date, 'created');
            $todayWhere1 .= " AND status =1 AND uniacid =" . UNIACID;
            $todayMoney1 = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('withdrawals') . " WHERE {$todayWhere1}");

            $todayWhere3 = $this->manger->getTime($date, $date, 'created');
            $todayWhere3 .= " AND status = 3 AND uniacid =" . UNIACID;
            $todayMoney3 = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('withdrawals') . " WHERE {$todayWhere3}");

            $balance = p_getcolumn('withdrawals', array('status' => 1), 'SUM(money)');
            include $this->template('withdrawals');
        }
    }

    public function doWebTreasure()
    {
        $op = $this->get('op');
        if ($op == 'addshow') {
            include $this->template('treasure_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $id = $this->get('id');
            $data = array(
                'name' => $this->get('name'),
                'cover_image' => $this->get('cover_image'),
                'issue_number' => $this->getIssueNumber(4),
                'number_copies' => $this->get('number_copies'),
                'image' => json_encode($this->get('image')),
                'price' => $this->get('price'),
                'max_number' => $this->get('max_number'),
                'is_down' => $this->get('is_down', 1),
                'type' => $this->get('type', 1),
                'created' => time(),
            );
            if ($data['type'] == 2) {
                $data['pwd'] = $this->get('pwd');
            }
            if ($id) {
                message(p_update('treasure', $data, array('id' => $id)) ? "修改成功" : "修改失败", $this->createWebUrl('treasure'));
            } else {
                $data['issue_number'] = $this->checkCode($data['issue_number']);
                message(p_insert('treasure', $data) ? "添加成功" : "添加失败", $this->createWebUrl('treasure'));
            }
        } elseif ($op == "sort") {
            $id = $this->get('id');
            $sort = $this->get('sort');
            $bool = p_update('treasure', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == "delete") {
            json('', p_update('treasure', array('is_delete' => 2), array('id' => $this->get('id'))) ? 1 : 0);
        } elseif ($op == 'editshow') {
            $treasure = p_get('treasure', array('id' => $this->get('id')));
            $treasure['image_data'] = $treasure ? json_decode($treasure['image']) : array();

            include $this->template('treasure_edit');
        } elseif ($op == 'treasure_member') {
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $treasure_id = $this->get('id');
            $table = prefix('treasure_code');
            $where = "uniacid={$this->w['uniacid']}";
            if ($treasure_id) {
                $where .= " AND treasure_id ={$treasure_id} ";
            }
            $name = $this->get('name');
            $nickname = $this->get('nickname');
            $member_id = $this->get('member_id');
            if ($member_id) {
                $where .= " AND member_id ={$member_id} ";
            }
            if ($nickname) {
                $member_ids = $this->manger->getMemberId($nickname);
                if ($member_ids) {
                    $where .= " AND member_id in ({$member_ids})";
                }
            }
            if ($name) {
                $treasure_ids = $this->getTreasureId($name);
                if ($treasure_ids) {
                    $where .= " AND treasure_id in ({$treasure_ids})";
                }
            }
            $list = p_fetchall("SELECT * FROM {$table} WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            if ($list) {
                foreach ($list as & $value) {
                    $value['member'] = p_get('member', array('id' => $value['member_id']), array('nickname', 'id'));
                    $value['treasure'] = p_get('treasure', array('id' => $value['treasure_id']), array('name'));
                    $value['treasure_member'] = p_get('treasure_member', array('id' => $value['treasure_member_id']), array('number_copies'));

                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);
            include $this->template('treasure_member');
        } elseif ($op == 'default') {
            $id = $this->get('id');

            $treasure = p_get('treasure_code', array('id' => $id));
            p_update('treasure_code', array('is_appoint' => 1), array('treasure_id' => $treasure['treasure_id'], 'is_appoint' => 2));

            $bool = p_update('treasure_code', array('is_appoint' => 2), array('id' => $id));
            message($bool ? '指定成功' : '指定失败', $this->createWebUrl('treasure'));
        } else {
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $table = prefix('treasure');
            $where = "uniacid={$this->w['uniacid']} AND is_delete =1";
            $list = p_fetchall("SELECT * FROM {$table} WHERE {$where} ORDER BY sort DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            if ($list) {
                $treasure_code = prefix('treasure_code');
                foreach ($list as & $value) {
                    $value['treasure_member'] = pdo_fetchcolumn("SELECT COUNT(*) FROM {$treasure_code} WHERE  uniacid={$this->w['uniacid']} AND treasure_id = {$value['id']}");
                    $value['shop_name'] = p_getcolumn('merchant', array('id' => $value['shop_id']), 'shop_name');
                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);
            include $this->template('treasure');
        }

    }

    public function doWebCategory()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addshow' || $op == 'editshow') {
            $category = p_get('category', array('id' => $id));
            include $this->template('category_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'title' => $this->get('title'),
                'status' => $this->get('status'),
                'sort' => $this->get('sort'),
            );
            $bool = $id ? p_update('category', $data, array('id' => $id)) : p_insert('category', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('category'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('category', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_update('category', array('status' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "status = 1 " . get_uniacid();
            $category = $this->manger->getTableList('category', $page, $where);
            include $this->template('category');
        }

    }


    public function doWebIntegralCategory()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addshow' || $op == 'editshow') {
            $category = p_get('integral_category', array('id' => $id));
            include $this->template('integral_category_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'title' => $this->get('title'),
                'describe' => $this->get('describe'),
                'status' => $this->get('status'),
                'sort' => $this->get('sort'),
            );
            $bool = $id ? p_update('integral_category', $data, array('id' => $id)) : p_insert('integral_category', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('integralCategory'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('integral_category', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_update('integral_category', array('is_delete' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $category = $this->manger->getTableList('integral_category', $page, $where);
            include $this->template('integral_category');
        }

    }

    public function doWebTask()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addshow' || $op == 'editshow') {
            $task = p_get('task', array('id' => $id));
            include $this->template('task_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'type' => $this->get('type'),
                'number' => $this->get('number'),
                'title' => $this->get('title'),
                'integral' => $this->get('integral'),
                'appid' => $this->get('appid'),
                'path' => $this->get('path'),
                'sort' => $this->get('sort'),
                'position' => $this->get('position'),
            );

            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('task', $data, array('id' => $id)) : p_insert('task', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('task'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('task', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('task', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $task = $this->manger->getTableList('task', $page, $where,'sort');
            if ($task['list']) {
                $type = array(
                    1 => '参加抽奖次数',
                    2 => '观看激励视频',
                    3 => '试玩其他小程序',
                    4 => '邀请好友'
                );
                $position = array(
                    1 => ' 首页悬浮',
                    2 => ' 任务页面',
                    1 => ' 首页任务同时显示',
                );
                foreach ($task['list'] as & $value) {
                    $value['type'] = $type[$value['type']];
                    $value['position'] = $position[$value['position']];
                }
            }
            include $this->template('task');
        }

    }

    public function doWebRedBag()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addshow' || $op == 'editshow') {
            $redBag = p_get('red_bag', array('id' => $id));
            include $this->template('red_bag_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'integral' => $this->get('integral'),
                'sign_days' => $this->get('sign_days'),
                'number' => $this->get('number'),
                'receive' => $this->get('receive'),
                'type' => $this->get('type'),
                'describe' => $this->get('describe'),
                'sort' => $this->get('sort'),
            );

            if ($data['type'] == 1) {
                $data['money'] = $this->get('money');
            } else {
                $data['start'] = $this->get('start');
                $data['end'] = $this->get('end');
            }
            if (!$id) {
                $data['created'] = time();
                if (p_getcolumn('red_bag', array(), 'COUNT(*)') >= 4) {
                    message("红包数量不超过4个", $this->createWebUrl('redBag'));
                }
            }
            $bool = $id ? p_update('red_bag', $data, array('id' => $id)) : p_insert('red_bag', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('redBag'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('red_bag', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('red_bag', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $redBag = $this->manger->getTableList('red_bag', $page, $where);
            include $this->template('red_bag');
        }

    }

    public function doWebGoods()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        if ($op == 'addshow' || $op == 'editshow') {
            $category = p_getall('category');
            if (empty($category)) {
                message("请选添加商品分类", $this->createWebUrl('category', array('op' => 'addshow')), 'warning');
            }
            $goods = p_get('goods', array('id' => $id));
            $goods['images'] = json_decode($goods['images'], true);
            include $this->template('goods_add');

        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'category_id' => $this->get('category_id'),
                'price' => $this->get('price'),
                'integral' => $this->get('integral'),
                'share_txt' => $this->get('share_txt'),
                'is_first' => $this->get('is_first'),
                'cover_image' => $this->get('cover_image'),
                'images' => json_encode($this->get('images')),
                'name' => $this->get('name'),
                'stock' => $this->get('stock'),
                'is_free' => $this->get('is_free'),
                'free' => $this->get('free'),
                'details' => $this->get('details'),
                'status' => $this->get('status'),
                'sort' => $this->get('sort'),
                'is_home' => $this->get('is_home'),
                'in_after' => $this->get('in_after'),
                'old_start' => $this->get('old_start'),
                'old_end' => $this->get('old_end'),
                'new_start' => $this->get('new_start'),
                'new_end' => $this->get('new_end'),
                'old_after_start' => $this->get('old_after_start'),
                'old_after_end' => $this->get('old_after_end'),
                'new_after_start' => $this->get('new_after_start'),
                'new_after_end' => $this->get('new_after_end'),
                'bargain_time' => $this->get('bargain_time'),
                'own_start' => $this->get('own_start'),
                'own_end' => $this->get('own_end'),
            );
            /*if (!$id){
                $data['created']= time();
            }*/

            $bool = $id ? p_update('goods', $data, array('id' => $id)) : p_insert('goods', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('goods'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('goods', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_update('goods', array('is_delete' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "is_delete = 1 " . get_uniacid();
            $goods = $this->manger->getTableList('goods', $page, $where);
            if ($goods['list']) {

                foreach ($goods['list'] as & $value) {
                    $value['category'] = p_getcolumn('category', array('id' => $value['category_id']), 'title');
                    $value['stock'] = $value['stock'] - p_getcolumn('order', array('goods_id' => $value['id'], 'status' => 2), 'COUNT(*)');

                }
            }

            include $this->template('goods');
        }

    }

    public function doWebIntegralGoods()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        if ($op == 'addshow' || $op == 'editshow') {
            $category = p_getall('integral_category');
            if (empty($category)) {
                message("请选添加商品分类", $this->createWebUrl('integralCategory', array('op' => 'addshow')), 'warning');
            }
            $goods = p_get('integral_goods', array('id' => $id));
            $goods['image'] = json_decode($goods['image'], true);
            include $this->template('integral_goods_add');

        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'category_id' => $this->get('category_id'),
                'type' => $this->get('type'),
                'original_price' => $this->get('original_price'),
                'goods_name' => $this->get('goods_name'),
                'share_title' => $this->get('share_title'),
                'image' => json_encode($this->get('image')),
                'exchange_type' => $this->get('exchange_type'),
                'money' => $this->get('money'),
                'exchange_number' => $this->get('exchange_number'),
                'cover_image' => $this->get('cover_image'),
                'is_free' => $this->get('is_free'),
                'free' => $this->get('free'),
                /*  'inventory_type'          => $this->get('inventory_type'),*/
                'inventory' => $this->get('inventory'),
                'introduce' => $this->get('introduce'),
                'allow_number' => $this->get('allow_number'),
                'sigin' => $this->get('sigin'),
                'is_home' => $this->get('is_home'),
                'sort' => $this->get('sort'),
            );

            if ($data['type'] == 2) {
                $relation_goods_id = $this->get('relation_goods_id');
                $pddData = $this->manger->detail($relation_goods_id);
                $data['relation_goods_id'] = $relation_goods_id;
                $data['goods_name'] = $pddData['goods_name'];
                $data['original_price'] = $pddData['min_normal_price'] / 100;
                $data['cover_image'] = $pddData['goods_image_url'];
                $data['image'] = json_encode($pddData['goods_gallery_urls']);
            }

            if ($data['type'] == 3) {
                $data['red_money'] = $this->get('red_money');
                $data['goods_name'] = $this->get('goods_name_s');
                $data['cover_image'] = $this->get('cover_image_s');
                $data['image'] = json_encode($this->get('image_s'));
                $data['inventory'] = $this->get('inventory_s');
                $data['allow_number'] = $this->get('allow_number_s');
                $data['sigin'] = $this->get('sigin_s');
            }
            if (!$id) {
                $data['created'] = time();
            }

            $data['status'] = $this->get('status');


            $bool = $id ? p_update('integral_goods', $data, array('id' => $id)) : p_insert('integral_goods', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('integralGoods'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('integral_goods', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_update('integral_goods', array('is_delete' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "is_delete = 1 " . get_uniacid();
            $goods = $this->manger->getTableList('integral_goods', $page, $where);
            if ($goods['list']) {
                $type = array(
                    1 => '实物',
                    2 => '拼多多',
                    3 => '红包'
                );
                foreach ($goods['list'] as & $value) {
                    $value['category'] = p_getcolumn('integral_category', array('id' => $value['category_id']), 'title');
                    $value['type'] = $type[$value['type']];

                }
            }
            include $this->template('integralGoods');
        }

    }

    public function doWebWarehouse()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addshow' || $op == 'editshow') {
            $warehouse = p_get('warehouse', array('id' => $id));
            include $this->template('warehouse_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'share_num' => $this->get('share_num'),
                'level' => $this->get('level'),
                'warehouse' => $this->get('warehouse'),
            );
            $bool = $id ? p_update('warehouse', $data, array('id' => $id)) : p_insert('warehouse', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('warehouse'));
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('warehouse', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('warehouse', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $warehouse = $this->manger->getTableList('warehouse', $page, $where);
            include $this->template('warehouse');
        }

    }


    public function doWebSignInReward()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'add' || $op == 'edit') {
            $data = array(
                'days' => (int)$this->get('days'),
                'type' => $this->get('type'),
                'reward' => $this->get('reward'),
            );
            if (!$id) {
                $data['created'] = time();
                if (p_get('signin_reward', array('days' => $data['days']))) {
                    message("天数已经存在请重新添加", $this->createWebUrl('signInReward', array('op' => 'addShow')), 'warning');
                }
            }
            if ($data['days'] < 1 || $data['days'] > 7) {
                message("天数必须是在1-7区间之前", $this->createWebUrl('signInReward', array('op' => 'addShow')), 'warning');
            }
            $bool = $id ? p_update('signin_reward', $data, array('id' => $id)) : p_insert('signin_reward', $data);
            message($bool ? "操作成功" : "操作失败", $this->createWebUrl('signInReward'));
        } elseif ($op == 'addShow' || $op == 'editShow') {
            $signInReward = p_get('signin_reward', array('id' => $id));
            include $this->template('signin_reward_add');
        } elseif ($op == 'delete') {
            $bool = p_update('signin_reward', array('is_delete' => 2), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $signInReward = $this->manger->getTableList('signin_reward', $page, $where);
            include $this->template('signin_reward');
        }
    }

    public function doWebOrder()
    {

        $op = $this->get('op');
        if ($op == "editshow") {
            $order = p_get('order', array('id' => $this->get('id')));
            $order['goods_name'] = p_getcolumn('goods', array('id' => $order['goods_id']), 'name');
            $order['nickname'] = p_getcolumn('member', array('id' => $order['member_id']), 'nickname');
            include $this->template('order_edit');
        } elseif ($op == "edit") {
            $id = $this->get('id');
            $courier_name = $this->get('courier_name');
            $courier_number = $this->get('courier_number');
            if (empty($id) || empty($courier_name) || empty($courier_number)) {
                message('发货信息不正确,请您检查你的发货信息', $this->createWebUrl('order'));
            }
            $treasure_order = array(
                'courier_name' => $courier_name,
                'courier_number' => $courier_number,
                'deliver_status' => 2,
                'delivery_time' => time(),
                'status' => 2
            );
            $bool = p_update('order', $treasure_order, array('id' => $id));
            message($bool ? '发货成功' : '发货失败', $this->createWebUrl('order'));
        } elseif ($op == 'success') {
            $id = $this->get('id');
            $bool = p_update('order', array('complete_time' => time(), 'deliver_status' => 3), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'cancel') {
            $id = $this->get('id');
            $bool = p_update('order', array('status' => 4), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $table = prefix('order');
            $where = "1 =1 AND uniacid={$this->w['uniacid']}";

            if ($deliver_status = $this->get('deliver_status')) {
                $where .= " AND deliver_status = {$deliver_status}";
            }
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            $goodsName = $this->get('goodsName');
            if ($goodsName) {
                $where .= " AND goods_id in ({$this->manger->getGoodsId($goodsName)})";
            }
            if ($type = $this->get('type')) {
                $where .= " AND type = {$type}";

            }
            if ($status = $this->get('status')) {
                $where .= " AND status = {$status}";

            }
            $list = p_fetchall("SELECT * FROM {$table} WHERE {$where} ORDER BY time_end DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            if ($list) {
                $sta = array(
                    1 => '未完成',
                    2 => '已完成',
                );
                $deliverStatus = array(
                    1 => '未发货',
                    2 => '已发货',
                    3 => '已完成'
                );
                foreach ($list as & $value) {
                    $value['member'] = p_get('member', array('id' => $value['member_id']));
                    $value['goods_name'] = p_getcolumn('goods', array('id' => $value['goods_id']), 'name');
                    $value['status'] = $sta[$value['status']];
                    $value['deliverStatus'] = $deliverStatus[$value['deliver_status']];
                    if (empty($value['address']) || empty($value['name']) || empty($value['phone'])) {
                        $member_address = $this->getAddress($value['member_id']);
                        $value['address'] = $member_address['address'];
                        $value['name'] = $member_address['name'];
                        $value['phone'] = $member_address['phone'];
                    }
                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);

            $date = date('Y-m-d', time());
            $todayWhere = $this->manger->getTime($date, $date, 'time_start');

            if ($status) {
                $todayWhere .= " AND status = 2";
            }
            $todayOrder = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('order') . " WHERE {$todayWhere}");


            $orderSucess = p_getcolumn('order', array('status' => 2), 'COUNT(*)');
            include $this->template('order');
        }

    }

    public function doWebIntegralOrder()
    {

        $op = $this->get('op');
        if ($op == "editshow") {
            $order = p_get('integral_order', array('id' => $this->get('id')));
            $order['goods_name'] = p_getcolumn('integral_goods', array('id' => $order['goods_id']), 'goods_name');
            $order['nickname'] = p_getcolumn('member', array('id' => $order['member_id']), 'nickname');
            include $this->template('integral_order_edit');
        } elseif ($op == "edit") {
            $id = $this->get('id');
            $courier_name = $this->get('courier_name');
            $courier_number = $this->get('courier_number');
            if (empty($id) || empty($courier_name) || empty($courier_number)) {
                message('发货信息不正确,请您检查你的发货信息', $this->createWebUrl('integralOrder'));
            }
            $treasure_order = array(
                'courier_name' => $courier_name,
                'courier_number' => $courier_number,
                'status' => 2,
                'delivery_time' => time(),
                'status' => 2
            );
            $bool = p_update('integral_order', $treasure_order, array('id' => $id));
            message($bool ? '发货成功' : '发货失败', $this->createWebUrl('integralOrder'));
        } elseif ($op == 'success') {
            $id = $this->get('id');
            $bool = p_update('integral_order', array('complete_time' => time()), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'cancel') {
            $id = $this->get('id');
            $bool = p_update('integral_order', array('status' => 4), array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $table = prefix('integral_order');
            $where = "1 =1 AND uniacid={$this->w['uniacid']}";

            if ($type = $this->get('type', 1)) {
                $where .= " AND type = {$type}";
            }
            $nickname = $this->get('nickname');
            if ($nickname) {
                $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
            }
            $list = p_fetchall("SELECT * FROM {$table} WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            if ($list) {
                $status = array(
                    1 => '未发货',
                    2 => '已发货',
                    3 => '已完成',
                    4 => '已取消',
                );
                foreach ($list as & $value) {
                    $value['member'] = p_get('member', array('id' => $value['member_id']));
                    if ($value['type'] == 2) {
                        $value['goods_name'] = p_getcolumn('integral_goods', array('id' => $value['relation_goods_id']), 'goods_name');
                    } else {
                        $value['goods_name'] = p_getcolumn('integral_goods', array('id' => $value['goods_id']), 'goods_name');
                    }
                    $value['state'] = $status[$value['status']];
                    if (empty($value['address']) || empty($value['name']) || empty($value['phone'])) {
                        $member_address = $this->getAddress($value['member_id']);
                        $value['address'] = $member_address['address'];
                        $value['name'] = $member_address['name'];
                        $value['phone'] = $member_address['phone'];
                    }
                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);

            $date = date('Y-m-d', time());
            $todayWhere = $this->manger->getTime($date, $date, 'created');

            $todayOrder = p_fetchcolumn("SELECT COUNT(*) FROM " . prefix('integral_order') . " WHERE {$todayWhere}");
            $orderSucess = p_getcolumn('integral_order', array('status' => 2), 'COUNT(*)');
            include $this->template('integral_order');
        }

    }

    public function doWebOrderInfo()
    {
        $page = $this->get('page');
        $where = "1 = 1 " . get_uniacid();

        if ($id = $this->get('id')) {
            $where .= " AND order_id = {$id}";
        }
        $bargain = $this->manger->getTableList('order_bargain', $page, $where);
        if ($bargain['list']) {
            foreach ($bargain['list'] as & $value) {
                $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                $value['goodName'] = p_getcolumn('goods', array('id' => $value['goods_id']), 'name');
            }
        }
        include $this->template('order_bargain');
    }

    public function doWebRule()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addShow' || $op == 'editShow') {
            $rule = p_get('rule', array('id' => $id));
            $rule['content'] = $rule['content'] ? json_decode($rule['content']) : array(0 => '');
            include $this->template('rule_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'title' => $this->get('title'),
                'content' => json_encode($this->get('content')),
                'position' => $this->get('position'),
                'sort' => $this->get('sort'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('rule', $data, array('id' => $id)) : p_insert('rule', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('rule'), $bool ? 'success' : 'error');
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('rule', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('rule', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $rule = $this->manger->getTableList('rule', $page, $where);

            include $this->template('rule');
        }

    }

    public function doWebProgram()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addShow' || $op == 'editShow') {
            $program = p_get('program', array('id' => $id));
            include $this->template('program_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'icon' => $this->get('icon'),
                'name' => $this->get('name'),
                'appid' => $this->get('appid'),
                'path' => $this->get('path'),
                'position' => $this->get('position'),
                'sort' => $this->get('sort'),
                'type' => $this->get('type'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('program', $data, array('id' => $id)) : p_insert('program', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('program'), $bool ? 'success' : 'error');
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('program', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('program', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $program = $this->manger->getTableList('program', $page, $where);
            $isPopularitye = $this->rising->isPopularitye();
            include $this->template('program');
        }

    }

    public function doWebAdvertisement()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == 'addShow' || $op == 'editShow') {
            $advertisement = p_get('advertisement', array('id' => $id));
            include $this->template('advertisement_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'image' => $this->get('image'),
                'title' => $this->get('title'),
                'position' => $this->get('position'),
                'type' => $this->get('type'),
                'appid' => $this->get('appid'),
                'url' => $this->get('url'),
                'sort' => $this->get('sort'),
                'group_id' => $this->get('group_id'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('advertisement', $data, array('id' => $id)) : p_insert('advertisement', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('advertisement'), $bool ? 'success' : 'error');
        } elseif ($op == 'sort') {
            $sort = (int)$this->get('sort');
            $bool = p_update('advertisement', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('advertisement', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $advertisement = $this->manger->getTableList('advertisement', $page, $where);

            if ($advertisement['list']) {
                $type = array(
                    '1' => '当前小程序',
                    '2' => '其他小程序',
                    '3' => 'h5',
                    '4' => '流量主'
                );
                $position = array(
                    1 => '首页上方',
                    2 => '首页中间',
                    3 => '积分商城页'
                );
                foreach ($advertisement['list'] as & $value) {
                    $value['type'] = $type[$value['type']];
                    $value['position'] = $position[$value['position']];

                }
            }
            include $this->template('advertisement');
        }

    }

    protected function getImages($id, $images)
    {
        if (!$id) {
            return getImage($images);
        }
        if ($id) {
            if (strpos($images, 'http') !== false) {
                return $images;
            } else {
                return getImage($images);
            }
        }

    }

    public function doWebVideoCategory()
    {
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'addShow' || $op == 'editShow') {
            $videoCategory = p_get('video_category', array('id' => $id));
            include $this->template('videoCategory_add');

        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'name' => $this->get('name'),
                'sort' => $this->get('sort'),
                'status' => $this->get('status'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('video_category', $data, array('id' => $id)) : p_insert('video_category', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('videoCategory'), $bool ? 'success' : 'error');
        } elseif ($op == 'sort') {
            $sort = $this->get('sort');
            $bool = p_update('video_category', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('video_category', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $table = prefix('video_category');
            $where = "uniacid = {$this->w['uniacid']} AND 1 = 1";
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $list = pdo_fetchall('SELECT * FROM ' . $table . " WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);
            include $this->template('videoCategory');
        }
    }


    public function doWebVideoAuthor()
    {
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'addShow' || $op == 'editShow') {
            $videoAuthor = p_get('video_author', array('id' => $id));
            include $this->template('videoAuthor_add');

        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'name' => $this->get('name'),
                'head' => $this->get('head'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('video_author', $data, array('id' => $id)) : p_insert('video_author', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('videoAuthor'), $bool ? 'success' : 'error');
        } elseif ($op == 'sort') {
            $sort = $this->get('sort');
            $bool = p_update('video_author', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('video_author', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $table = prefix('video_author');
            $where = "uniacid = {$this->w['uniacid']} AND 1 = 1";
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $list = pdo_fetchall('SELECT * FROM ' . $table . " WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);
            include $this->template('videoAuthor');
        }
    }


    public function doWebTimeSlot()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            $timeSlot = p_get('time_slot', array('id' => $id));
            include $this->template('time_slot_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'start' => $this->get('start'),
                'end' => $this->get('end'),
            );
            $bool = !empty($id) ? p_update('time_slot', $data, array('id' => $id)) : p_insert('time_slot', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('timeSlot'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('time_slot', array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $timeSlot = $this->manger->getTableList('time_slot', $page, $where);
            include $this->template('time_slot');
        }
    }


    public function doWebNavigation()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        $siteRoot = $this->siteRoot;
        $modular_name = $this->gpc['m'];
        if ($op == 'add' || $op == 'edit') {
            $data = array(
                'name' => $this->get('name'),
                'position' => $this->get('position'),
                'path' => $this->get('path'),
                'selection_image' => $this->get('selection_image'),
                'unchecked_images' => $this->get('unchecked_images'),
                'selection_color' => $this->get('selection_color'),
                'unchecked_color' => $this->get('unchecked_color'),
                'sort' => $this->get('sort'),
            );
            if (!$id) {
                $data['created'] = time();
            }
            $bool = $id ? p_update('navigation', $data, array('id' => $id)) : p_insert('navigation', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('navigation'), $bool ? 'success' : 'error');

        } elseif ($op == 'editShow' || $op == 'addShow') {
            $navigation = p_get('navigation', array('id' => $id));
            include $this->template('navigation_add');
        } elseif ($op == 'sort') {
            $sort = $this->get('sort');
            $bool = p_update('navigation', array('sort' => $sort), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'delete') {
            $bool = p_delete('navigation', array('id' => $id));
            json('', $bool ? 1 : 0);
        } else {
            $table = prefix('navigation');
            $where = "uniacid = {$this->w['uniacid']} AND 1 = 1";
            $pindex = max(1, intval($this->get('page')));
            $psize = 20;
            $list = pdo_fetchall('SELECT * FROM ' . $table . " WHERE {$where} ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
            $position = array(
                'index_home' => '首页',
                'goods_category' => '砍价商城',
                'sign_shop' => '积分商城',
                'my_index' => '我的',
                'sign_index' => '签到任务页',
                'luck_index' => ' 抽奖列表',
            );
            if ($list) {
                foreach ($list as & $value) {
                    $value['position'] = $position[$value['position']];
                }
            }
            $total = pdo_fetchcolumn("SELECT COUNT(*) FROM {$table} WHERE {$where}");
            $pager = pagination($total, $pindex, $psize);

            include $this->template('navigation');
        }
    }

    public function doWebPayOrder()
    {
        $where = "1=1" . get_uniacid();
        $nickname = $this->get('nickname', '');
        if (!empty($nickname)) {
            $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
        }
        $member_id = $this->get('member_id');
        if ($member_id) {
            $where .= " AND member_id={$member_id}";
        }
        $status = $this->get('status', 0);
        if ($status > 0) {
            $where .= " AND status={$status}";
        }
        $payOrder = $this->manger->getTableList('pay_order', $this->get('page'), $where);
        if ($payOrder['list']) {
            $type = array(
                1 => '购买商品',
                2 => '积分订单'
            );
            foreach ($payOrder['list'] as & $value) {
                $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                $value['type'] = $type[$value['type']];
            }
        }
        include $this->template('payOrder');
    }

    public function doWebIntegralLog()
    {
        $page = $this->get('page');
        $where = "1 = 1 " . get_uniacid();
        $nickname = $this->get('nickname');
        if ($nickname) {
            $where .= " AND member_id in ({$this->manger->getMemberId($nickname)})";
        }
        $member_id = $this->get('member_id');
        if ($member_id) {
            $where .= " AND member_id={$member_id}";
        }
        $integralLog = $this->manger->getTableList('integral_log', $page, $where);
        if ($integralLog['list']) {
            $type = array(
                1 => '签到',
                2 => '签到翻倍',
                3 => '兑换礼品',
                4 => '完成任务',
                5 => '兑换道具',
                6 => '兑换红包',
                7 => '绑定手机号',
                8 => '授权个人信息',
                9 => '邀请好友',
                10 => '兑换积分商品',
                11 => '获取二维码',
            );
            foreach ($integralLog['list'] as & $value) {
                $value['mold'] = in_array($value['type'], array(1, 2, 4, 6, 7, 8, 9)) ? '+' : '-';
                $value['type'] = $type[$value['type']];
                $value['nickname'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
            }
        }
        include $this->template('integralLog');
    }


    public function doWebLuckGoodsInfo()
    {

        $page = $this->get('page');
        $where = "type = 1 " . get_uniacid();
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'success') {
            $bool = p_update('luck_goods_info', array('status' => 3), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'cancel') {
            $bool = p_update('luck_goods_info', array('status' => 4), array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'del') {
            $bool = p_delete('luck_goods_info', array('id' => $id));
            json('', $bool ? 1 : 0);
        } elseif ($op == 'deleteAll') {
            $taskIds = $this->get('taskIds');
            $ids = explode(',', $taskIds);
            if ($ids) {
                foreach ($ids as $val) {
                    p_delete('luck_goods_info', array('id' => $val));
                }
                json('', 1);
            }
            json('', 0);
        } else {
            $luck_goods_info = $this->manger->getTableList('luck_goods_info', $page, $where);
            $status = array(
                1 => '未发货',
                2 => '已发货',
                3 => '已完成',
                4 => '已取消'
            );
            if ($luck_goods_info['list']) {
                foreach ($luck_goods_info['list'] as & $value) {
                    $value['status_str'] = $status[$value['status']];
                    $value['initiator'] = p_getcolumn('member', array('id' => $value['member_id']), 'nickname');
                    $value['winners'] = p_getcolumn('member', array('id' => $value['in_member_id']), 'nickname');
                }
            }
            include $this->template('luck_goods_info');
        }

    }


    public function doWebRoll()
    {
        $op = $this->get('op');
        $id = $this->get('id');
        if ($op == "addShow" || $op == 'editShow') {
            $roll = p_get('roll', array('id' => $id));
            include $this->template('roll_add');
        } elseif ($op == 'add' || $op == 'edit') {
            $data = array(
                'image' => $this->get('image'),
                'content' => $this->get('content'),

            );
            $bool = !empty($id) ? p_update('roll', $data, array('id' => $id)) : p_insert('roll', $data);
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('roll'), $bool ? 'success' : 'error');
        } elseif ($op == 'delete') {
            $id = $this->get('id');
            p_delete('roll', array('id' => $id));
            json('1');
        } else {
            $page = $this->get('page');
            $where = "1 = 1 " . get_uniacid();
            $roll = $this->manger->getTableList('roll', $page, $where);
            include $this->template('roll');
        }

    }


    public function doWebVoteSend()
    {
        $id = $this->get('id');
        $op = $this->get('op');
        if ($op == 'send') {
            if (!p_get('luck_goods_info', array('id' => $id))) {
                message('订单不存在,请重新选择', $this->createWebUrl('luckGoodsInfo'), 'error');
            }
            $data = array(
                'status' => $this->get('status'),
                'courier_name' => $this->get('courier_name'),
                'courier_number' => $this->get('courier_number'),
            );
            $bool = p_update('luck_goods_info', $data, array('id' => $id));
            message($bool ? '操作成功' : '操作失败', $this->createWebUrl('luckGoodsInfo'), $bool ? 'success' : 'error');
        } else {
            $luckSendData = p_get('luck_goods_info', array('id' => $id));
            if (!$luckSendData) {
                message('订单不存在,请重新选择', $this->createWebUrl('luckGoodsInfo'), 'error');
            }
            $luckSendData['prizewinner'] = p_getcolumn('member', array('id' => $luckSendData['in_member_id']), 'nickname');
            $luckSendData['initiator'] = p_getcolumn('member', array('id' => $luckSendData['member_id']), 'nickname');
            $member = p_get('address', array('member_id' => $luckSendData['in_member_id']));
            include $this->template('luckSend');

        }
    }

    /**
     *
     * 地址信息
     * @param $member_id
     * @return bool
     */
    public function getAddress($member_id)
    {
        $table = prefix('address');
        return p_fetch("SELECT * FROM {$table} WHERE member_id = {$member_id}  ORDER BY id DESC");
    }

    /**
     * 获取商品ids
     * @param $treasure_name
     * @return bool
     */
    protected function getTreasureId($treasure_name)
    {
        $table = prefix('treasure');
        $where = '1=1';
        $where .= " AND name LIKE '%{$treasure_name}%' ";
        $treasureInfo = p_fetchall("SELECT id FROM {$table} WHERE {$where} ORDER BY id DESC ");
        if ($treasureInfo) {
            foreach ($treasureInfo as $item) {
                $treasure_id[] = $item['id'];

            }
            return implode(',', $treasure_id);
        }
        return '';
    }

    public function checkCode($code = '')
    {
        if (p_get('treasure', array('issue_number' => $code))) {
            return $this->checkCode($this->getIssueNumber(12));
        }
        return $code;
    }

    /**
     * @param $length
     * @return string
     */
    protected function getIssueNumber($length)
    {
        $str = '201812345678998765412307899638527411236987412';
        $len = strlen($str) - 1;
        $randStr = '';
        for ($i = 0; $i < $length; $i++) {
            $num = mt_rand(0, $len);
            $randStr .= $str[$num];
        }
        $str = date('Ymd') . $randStr;
        return $str;
    }

    public function doWebEditorUpload()
    {
        if (!isset($_FILES['imgFile'])) {
            json('请上传图片', 0);
        }
        load()->func('file');
        $reslut = file_upload($_FILES['imgFile']);
        if (isset($reslut['errno'])) {
            json($reslut['message'], 0);
        }
        $pic = '/' . $reslut['path'];

        if (is_oss()) {
            $remotestatus = file_remote_upload($reslut['path']);
            if (is_error($remotestatus)) {
                json('远程附件上传失败', 0);
            }
        }

        die(json_encode(array('error' => 0, 'url' => getImage($pic))));
    }

    /**
     * 获取参数
     * @param $key
     * @param string $default
     * @return mixed|string
     *
     */
    private function get($key, $default = '')
    {
        return isset($this->gpc[$key]) ? $this->gpc[$key] : $default;
    }

}